$("header").load("header.html");
$("footer").load("footer.html");

$(".one-level-title").click(function() {
    if ($(this).next().css("maxHeight") == "400px") {

        $(this).children(".type-active").html("+");
        $(this).next().stop().animate({
            maxHeight: 0
        })
    } else {
        $(this).children(".type-active").html("-");
        $(this).next().stop().animate({
            maxHeight: 400
        })
    }

})



// 从数据库获取数据渲染页面goods
function loadGoods() {
    let loginId = localStorage;
    let allGoods = JSON.parse(loginId.goods)
    allGoods.length = 0;
    for (let index in allGoods) {
        allGoods.length++;
    }

    // 0id: "1001"
    // 0img: "img-goods/1001.jpg"
    // 0money: "79"
    // 0text: "训练系列男子短袖T恤ATSR369-3"
    for (let i = 0, s = 1; i < allGoods.length / 4 - 1; i++, s++) {
        let goodsList = document.querySelector(".ui-goods-list");
        // console.log(allGoods[i +"img"] + "0.jpg");
        // goodsList.style.backgroundColor = "red ";
        goodsList.innerHTML += `<div class="merchandise-news"><a class="skip-goods-detail-page" href="detailPage.html" target="_blank" goodsId="${s}"><div class="merchandise-news-img"><img src="${allGoods[i + "img"]}0.jpg" alt=""></div></a><div class="merchandise-news-img-little"><img class="all-goods-title-one" src="${allGoods[i + "img"]}0.jpg" alt=""><img class="all-goods-title-two" src="${allGoods[i + "img"]}1.jpg" alt=""></div><p class="merchandise-news-introduce">${allGoods[i +"text"]}</p><div class="merchandise-goods-price"><div class="merchandise-activity-price">￥${allGoods[i +"money"]}</div><div class="merchandise-tag-price">￥${allGoods[i +"money"]}</div></div></div>`;
    }
    linkDetailPage();
}

loadGoods();

function linkDetailPage() {
    $(".all-goods-title-one").click(function() {
        $(this).css("border", "1px solid #db3b3b").next().css("border", "1px solid #e7e7e7").parent().prev().find('img').attr("src", $(this).attr("src"));
        // $(this)
    })
    $(".all-goods-title-two").click(function() {
        $(this).css("border", "1px solid #db3b3b").prev().css("border", "1px solid #e7e7e7").parent().prev().find('img').attr("src", $(this).attr("src"));
    })

    $(".skip-goods-detail-page").click(function() {
        let loginId = localStorage;
        loginId.id = $(this).attr("goodsId")
            // console.log()
        $(location).attr('href', 'detailPage.html');
        return false;
    })
}